/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ec.edu.espe.distribuidas.aseguradora.dao;

import ec.edu.espe.distribuidas.aseguradora.modelo.Cliente;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author alejandro
 */
@Stateless
public class ClienteFacade extends AbstractFacade<Cliente> {
    @PersistenceContext(unitName = "ec.edu.espe.distribuidas.aseguradora_AseguradoraJSF-ejb_ejb_1PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ClienteFacade() {
        super(Cliente.class);
    }
    
    public List<Cliente> findByName(String nombre) {
        Query qry = this.getEntityManager().createQuery("SELECT obj FROM Cliente obj WHERE obj.cliNombre LIKE '%"+nombre+"%'");
        return qry.getResultList();
    }
      public Cliente findPorCodigo(String codigo)
    {
        Query qry=this.getEntityManager().createQuery("SELECT obj FROM Cliente obj WHERE obj.codCliente="+codigo);
        return (Cliente)qry.getResultList().get(0);
    }
    
}
